package com.rimi.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.rimi.bean.Attentions;
import com.rimi.bean.User;
import com.rimi.service.AttentionsService;
import com.rimi.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/user2")
public class User2contollrt {

    @Autowired
    private AttentionsService attentionsService;

    @Autowired
    private UserService userService;

    @RequestMapping("/user")
    public String attention(Model model , Integer userId, HttpSession session){
        User user = (User) session.getAttribute("user");
        userId = user.getUserId();
        List<Attentions> attentions = attentionsService.selectList(new EntityWrapper<Attentions>().eq("user_id",userId));
        List<User> users = userService.selectList(new EntityWrapper<User>().eq("user_id",userId));
        List<User> list2 = new ArrayList();
        for (User user1 : users) {
            user = userService.selectById(user1.getUserId());
            list2.add(user);
        }

        List<User> list = new ArrayList();
        for (Attentions attention : attentions) {
            user = userService.selectById(attention.getAttentionId());
            list.add(user);
        }


        model.addAttribute("attention",list);
        model.addAttribute("user",list2);
        return "follow";

    }
}
